import pyautogui
import time
import pyperclip


def copy_kafka_messages(count=100):
    # 点击 Kafka Tool 窗口
    pyautogui.click(100, 200)  # 调整坐标

    for i in range(count):
        # 选择消息 (假设每条消息高度30像素)
        pyautogui.click(150, 250 + i * 30)
        time.sleep(0.5)

        # 复制消息
        pyautogui.hotkey('ctrl', 'c')
        time.sleep(0.5)

        # 获取剪贴板内容并保存
        message = pyperclip.paste()
        with open('kafka_messages.txt', 'a', encoding='utf-8') as f:
            f.write(f"Message {i + 1}:\n")
            f.write(message + "\n\n")

        print(f"已复制第 {i + 1} 条消息")


copy_kafka_messages(50)
